<?php
// $Id: TestCase.php 27 2010-11-16 12:49:54Z mjohnson60@gmail.com $

define('ROOT', dirname(dirname(__FILE__)));

require_once('simpletest/autorun.php');

require_once('Expectation.php');

require_once(ROOT . '/includes/common.inc');
require_once(ROOT . '/libraries/Initializer.php');
require_once(ROOT . '/libraries/Theme.php');
require_once(ROOT . '/libraries/Athena.php');

include_once(ROOT . '/libraries/debug/Debug.php');

/**
 * Enter description here ...
 * @author markjohnson
 */
abstract class TestCase extends UnitTestCase 
{
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $usesConfig = FALSE;
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $usesDb = FALSE;
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $usesSessions = FALSE;
	
	/**
	 * @var unknown_type Enter description here ...
	 */
	var $usesCache = FALSE;
	
	private $initializer = NULL;
	
	/**
	 * Enter description here ...
	 */
	public function __construct() 
	{
		foreach ($_ENV as $key => $value) 
		{
			$_SERVER[$key] = $value;
		}
		
		$_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__FILE__));
		chdir($_SERVER['DOCUMENT_ROOT']);
		ini_set('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']);
		$_SERVER['SCRIPT_NAME'] = '/index.php';
		
		$_SERVER['HTTP_HOST'] = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'mbpwin.local';
		
		if ($this->usesConfig) 
		{
			$init_level = INITIALIZE_CONFIGURATION;
			
			if ($this->usesDb) 
			{
				$init_level = INITIALIZE_DATABASE;
				
				if ($this->usesSessions) 
				{
					$init_level = INITIALIZE_SESSION;
					
					if ($this->usesCache) 
					{
						$init_level = INITIALIZE_CACHE;
					}
				}
			}
			
			$this->initializer = new Initializer($init_level);
			Initializer::initialize($init_level);
		}
		
		$_GET['q'] = substr($_SERVER['REQUEST_URI'], 0, strlen($_SERVER['REQUEST_URI']) - 4);
	}
	
	/**
	 * Enter description here ...
	 * 
	 * @param unknown_type $value
	 * @param unknown_type $message
	 * @return boolean
	 */
	public function assertEmpty($value, $message = '%s') 
	{
		return $this->assert(new EmptyExpectation(), $value, $message);
	}
	
	/**
	 * Enter description here ...
	 * 
	 * @param unknown_type $value
	 * @param unknown_type $message
	 * @return boolean
	 */
	public function assertNotEmpty($value, $message = '%s') 
	{
		return $this->assert(new NotEmptyExpectation(), $value, $message);
	}
	
	/**
	 * Enter description here ...
	 * 
	 * @param unknown_type $value
	 * @param unknown_type $message
	 * @return boolean
	 */
	public function assertContains($first, $second, $message = '%s') 
	{
		return $this->assert(new ContainsExpectation($first), $second, $message);
	}
}